package com.googlecode.eightqueenshaggle;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainMenuController extends Activity implements OnClickListener {

	Button buttonNewGame, buttonSolExp, buttonQuit;

	static final int DIALOG_GAME_TYPE = 0;

	public MainMenuController myself = this;
	
	private android.os.Vibrator vibrator = null;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_menu);
		Log.e("test", "1");
		buttonNewGame = (Button) findViewById(R.id.ButtonNewGame);
		buttonSolExp= (Button) findViewById(R.id.ButtonSolutionExplorer);
		buttonQuit = (Button) findViewById(R.id.ButtonQuit);

		buttonNewGame.setOnClickListener(this);
		buttonSolExp.setOnClickListener(this);
		buttonQuit.setOnClickListener(this);
	
		//make the phone vibrate
		vibrator = (android.os.Vibrator)getSystemService(VIBRATOR_SERVICE);
		long[] pattern = { 0, 300, 100, 400 };
		vibrator.vibrate(pattern, -1);
	
	}

	protected Dialog onCreateDialog(int id) {
	    
		Dialog dialog = null;
	    
		switch(id) {
	    case DIALOG_GAME_TYPE:
	        
	    	// do the work to define the game type dialog
	    	final CharSequence[] items = { "Classical Puzzle (8x8 field, 8 queens)", "...", "...", "..."};

			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setTitle("Select Game Type");
			builder.setItems(items, new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog, int item) {

					if (item == 0) {


						 //start the BoardView Activity
						//TODO: Is there a more elegant way to express the current context?
						Intent intent = new Intent(myself,
								 					BoardViewController.class);
						 startActivity(intent);
						 finish();

					}else{
						
						 Toast.makeText(getApplicationContext(), "Sorry, not yet available",
								 Toast.LENGTH_SHORT).show();
						
					}

				}
			});

			dialog = builder.create();
	    	
	    	
	        break;
	    }
	    
	    
	    return dialog;
	}
	
	public void onClick(View v) {

		// user wants to play a new game with GUI
		if (v == buttonNewGame) {

			showDialog(DIALOG_GAME_TYPE);

		} else if (v == buttonSolExp) {
						
			
			Intent intent = new Intent(this, SolutionExplorerViewController.class);
			startActivity(intent);
			finish();
		
		} else if (v == buttonQuit) {
			
			
			//this.finish();
			
			//temp. change
			Intent intent = new Intent(this, HaggleTestViewController.class);
			startActivity(intent);
			finish();
			
			
		}
	}
}
